<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/11/20
 * Time: 16:48
 */
namespace common\sources\read\taobao;

use common\models\craftsman\TaoBao;

class TaoBaoAccess implements  ITaoBaoAccess
{
    public function getTaoBaoList($buyerId)
    {
        return TaoBao::find()
            ->select("id,tbname,pro_name,pro_code,city_name,city_code,area_name,area_code,addr,audit_status,takephone,reason,takename,takephone,reason,freeze,freeze_reason,is_receive_task")
            ->where(["buy_id" =>$buyerId,'is_display'=>1])
            ->asArray()
            ->all();
    }

    public function getList($buyerId)
    {
        return TaoBao::find()
                ->select("id,tbname,pro_name,pro_code,city_name,city_code,area_name,area_code,addr,audit_status,takephone,reason,takename,takephone,reason,freeze,freeze_reason,is_receive_task")
                ->where(["buy_id" =>$buyerId,'is_display'=>1,"audit_status" =>2,"freeze" =>2])
                ->asArray()
                ->all();
    }
    //查看绑定个数
    public function getCount($buyerId)
    {
        return TaoBao::find()
                ->where(['buy_id'=>$buyerId])
                ->count();

    }
    public function getTaoBaoDetail($tb_id)
    {
        return TaoBao::find()
            ->select("id,tbname,pro_name,pro_code,city_name,city_code,area_name,area_code,addr,audit_status,takephone,reason,takename,buy_id,sex,zfbname,zfbage,zfbname_img,ip_img,tqz_img,takeaddr,zfbhb_img,
            create_time,freeze,is_receive_task")
            ->where(["id" =>$tb_id])
            ->asArray()
            ->one();
    }

    public function getTaobao($tbname)
    {
        return TaoBao::find()
            ->select("id,tbname,pro_name,pro_code,city_name,city_code,area_name,area_code,addr,audit_status,takephone,reason,takename,buy_id,sex,zfbname,zfbage,zfbname_img,ip_img,tqz_img,takeaddr,zfbhb_img,create_time,freeze,is_receive_task")
            ->where(["tbname" =>$tbname])
            ->asArray()
            ->one();
    }
    public function getTaoBaoPhone($phone)
    {
        return TaoBao::find()
            ->select("id,tbname,pro_name,pro_code,city_name,city_code,area_name,area_code,addr,audit_status,takephone,reason,takename,buy_id,sex,zfbname,zfbage,zfbname_img,ip_img,tqz_img,takeaddr,zfbhb_img,create_time,freeze,is_receive_task")
            ->where(["takephone" =>$phone])
            ->asArray()
            ->one();
    }
    //同一个用户下支付宝名称唯一
    public function getTaoBaoByZfb($data)
    {
        return TaoBao::find()
            ->select("id,tbname,pro_name,pro_code,city_name,city_code,area_name,area_code,addr,audit_status,takephone,reason,takename,buy_id,sex,zfbname,zfbage,zfbname_img,ip_img,tqz_img,takeaddr,zfbhb_img,create_time,freeze,is_receive_task")
            ->where(["buy_id" =>$data['buy_id'],"zfbname" => $data['zfbname']])
            ->asArray()
            ->one();
    }

}